package com.ant.storage.controller;


import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.PlannedDto;
import com.ant.storage.dto.PolicyDto;
import com.ant.storage.service.IPlannedService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-11-07
 */
@RestController
@RequestMapping("/planned")
public class PlannedController {

    @Autowired
    IPlannedService plannedService;

    @ApiOperation(value = "获取领料数据列表")
    @GetMapping("/getPlannedList")
    public ResultPage getPlannedList(PlannedDto dto) {
        return ResultPage.success("获取成功",plannedService.querylist(dto));
    }


    @ApiOperation(value = "添加计划采购单")
    @PostMapping("/addPlan")
    public ResultVo addPlan(@Valid @RequestBody PlannedDto dto, BindingResult bindingResult) {
        return plannedService.addPlan(dto,bindingResult);
    }


    @ApiOperation(value = "计划采购通过")
    @GetMapping("/adoptPlannedApply/{id}")
    public ResultVo adoptPlannedApply(@PathVariable(value = "id",required = false) Integer id) {
        return plannedService.adoptPlannedApply(id);
    }

    @ApiOperation(value = "通过id获取计划采购单")
    @GetMapping("/getPlannedDetailsById/{id}")
    public ResultVo getPlannedDetailsById(@PathVariable(value = "id",required = false) Integer id) {
        return plannedService.getPlannedDetailsById(id);
    }

    @ApiOperation(value = "分单生成采购单")
    @PostMapping("/policyGenerateSubscribe")
    public ResultVo policyGenerateSubscribe(@RequestBody PolicyDto dto) {
        return plannedService.policyGenerateSubscribe(dto);
    }

    @ApiOperation(value = "查看计划采购详情 ")
    @GetMapping("/getPolicySubscribe/{id}")
    public ResultVo getPolicySubscribe(@PathVariable(value = "id",required = false) Integer id) {
        return plannedService.getPolicySubscribe(id);
    }

    @ApiOperation(value = "查看计划采购详情 ")
    @GetMapping("/getPlannedProcurement/{warehouseId}")
    public ResultVo getPlannedProcurement(@PathVariable(value = "warehouseId",required = false) Integer warehouseId) {
        return plannedService.getPlannedProcurement(warehouseId);
    }

}
